package tst
class Apply {
	static {
		Object.metaClass.apply= {Closure rule ->
			println "Apply delegate is " + delegate + ", this is " + this
			with(rule)
		}
	}
}

class Outer {
	static Closure rule = {
		println "Outer delegate is " + delegate + ", this is " + this
		apply(Inner.rule)
	}
}

class Inner {
	static Closure rule = {
		println "Inner delegate is " + delegate + ", this is " + this
		apply(Sub.rule)
	}
}

class Sub {
	static Closure rule = {
		println "Sub delegate is " + delegate + ", this is " + this
		println varb;
	}
}


varb = 'hello';

new Apply();

apply(Outer.rule)